package com.itcv.mybatis.demo;

import com.itcv.mybatis.demo.dao.StudentMapper;
import com.itcv.mybatis.demo.model.FemaleStudent;
import com.itcv.mybatis.demo.model.Student;
import com.itcv.mybatis.demo.model.StudentHealthFemale;
import com.itcv.mybatis.demo.model.StudentLecture;
import com.itcv.mybatis.demo.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class DiscriminatorTest {
    public static void main(String[] args) {
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionFactoryUtil.openSqlSession();
            StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
            Student stu =  studentMapper.getStudent(1);
            String str =  stu.getSex().toString().equals("1")?"男":"女";
            System.out.println("姓名："+stu.getStuName()+" 学号： "+stu.getSelfcardNo()+"性别： "+str);
            System.out.println("籍贯："+stu.getStudentSelfcard().getNativeAddress());
            System.out.println("课程 ：              成绩：           ");
            for(StudentLecture studentLecture :stu.getStudentLectureList()){
                System.out.println(studentLecture.getLecture().getLectureName()+"              "+studentLecture.getScore());
            }
            System.out.println("健康信息");
            if(stu.getSex().toString().equals("1")){
                FemaleStudent femaleStudent = (FemaleStudent) stu;
                List<StudentHealthFemale> studentHealthFemaleList = femaleStudent.getStudentHealthFemaleList();
                for (StudentHealthFemale female: studentHealthFemaleList) {
                    System.out.println(female.getUterus());
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            sqlSession.close();
        }
    }
}
